﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
    <script>
        var entity = {};
        layui.use(['jquery', 'form', 'laydate', 'common', 'optimizeSelectOption'], function () {
            var form = layui.form,
                $ = layui.$,
                common = layui.common;
            //权限字段
            common.authorizeFields('adminform');
            if (!!entity && !!entity.TableColumn) {
                $('#F_EnCode').prop('disabled', true);
                $('#F_FullName').prop('disabled', true);
                $('#F_EnCode').val(entity.TableColumn);
                $('#F_FullName').val(entity.Remark);
            }
            else {
                $('#F_FullName').parent().parent().remove();
                $('#F_NewName').parent().parent().find("label").html("名称");
            }
            form.render();
            wcLoading.close();
            //监听提交
            var lock = false;
            form.on('submit(saveBtn)', function (data) {
                if (!lock) {
                    lock = true;
                    var index = parent.layer.load(0, {
                        shade: [0.5, '#000'], //0.1透明度的背景
                    });
                    var postData = {};
                    postData.TableColumn = data.field.F_EnCode;
                    postData.Remark = data.field.F_NewName;
                    if (!!entity) {
                        postData.F_Id = entity.F_Id;
                    }
                    else {
                        postData.F_Id = uuid();
                    }
                    var tempdata = common.currentWindow().layui.table.cache.currentTableId;
                    if (!!entity) {
                        for (var i = 0; i < tempdata.length; i++) {
                            if (entity.F_Id == tempdata[i].F_Id) {
                                tempdata[i].TableColumn = postData.TableColumn;
                                tempdata[i].Remark = postData.Remark;
                                break;
                            }
                        }
                    }
                    else {
                        for (var i = 0; i < tempdata.length; i++) {
                            if (tempdata[i].TableColumn == postData.TableColumn) {
                                common.modalMsg("操作失败,编号重复", "error");
                                lock = false;
                                return false;
                            }
                        }
                        tempdata.push(postData);
                    }
                    common.modalMsg("操作成功", "success");
                    common.currentWindow().layui.table.reload('currentTableId', {
                        data: tempdata
                    });
                    parent.layer.close(index);
                    common.modalClose();
                }
                return false;
            });
        });
        function initForm(data) {
            entity = data;           
        }
    </script>
<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form " lay-filter="adminform">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input type="text" id="F_EnCode" maxlength="50" name="F_EnCode" class="layui-input ">
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="F_FullName" maxlength="50" name="F_FullName" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label required">新名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="F_NewName" maxlength="50" name="F_NewName" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <button class="layui-btn" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</body>
